//
//  CreditsViewController.m
//  PacIsBack
//
//  Created by Simon André on 08/02/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "CreditsViewController.h"
#import "CreditSectionViewController.h"
#import "Constants.h"

@implementation CreditsViewController

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

-(id) initCredits{
	if (self = [super init]) {
		UIScrollView* scrollView = [[UIScrollView alloc] init];
		[self setView:scrollView];
		//TODO
		NSMutableArray* sectionsList = [[NSMutableArray alloc] init];
		CreditSectionViewController* section = [[CreditSectionViewController alloc] initSectionWithName:@"Développement"];
		[sectionsList addObject:section];
		[section release];
		section = [[CreditSectionViewController alloc] initSectionWithName:@"Artwork"];
		[sectionsList addObject:section];
		[section release];
		section = [[CreditSectionViewController alloc] initSectionWithName:@"Ressources Graphiques"];
		[sectionsList addObject:section];
		[section release];
		section = [[CreditSectionViewController alloc] initSectionWithName:@"Musiques"];
		[sectionsList addObject:section];
		[section release];
		UITextView* creditsTitleView = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, iphoneWidth, creditSectionTextSize)];
		[creditsTitleView setEditable:NO];
		[creditsTitleView setScrollEnabled:NO];
		[creditsTitleView setText:@"Crédits"];
		[creditsTitleView setTextAlignment:UITextAlignmentCenter];
		[creditsTitleView setFont:[UIFont fontWithName:@"MarkerFelt-Thin" size:15.0]];
		[[self view] addSubview:creditsTitleView];
		[creditsTitleView release];
		
		CGFloat scrollHeight = [creditsTitleView frame].size.height;
		for (CreditSectionViewController* sectionElem in sectionsList) {
			[[self view] addSubview:[sectionElem view]];
			[[sectionElem view] setCenter:CGPointMake(iphoneHalfWidth, scrollHeight+[[sectionElem view] frame].size.height/2)];
			scrollHeight = scrollHeight+[[sectionElem view] frame].size.height;
		}
		[scrollView setContentSize:CGSizeMake(iphoneWidth, scrollHeight)];
		[scrollView release];
		[sectionsList release];
	}
	return self;
}

- (void)viewWillAppear:(BOOL)animated{
	[super viewWillAppear:animated];
	[[self navigationController] setNavigationBarHidden:NO animated:animated];
}

- (void)viewWillDisappear:(BOOL)animated{
	[super viewWillDisappear:animated];
	[[self navigationController] setNavigationBarHidden:YES animated:animated];
}

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
